package com.example.videoweb.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.videoweb.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public Object login(HttpServletRequest request, HttpSession session){
        JSONObject jsonObject = new JSONObject();
        String name = request.getParameter("username");
        String password = request.getParameter("password");
        boolean flag = adminService.verifyPassword(name,password);

        if(flag){
            jsonObject.put("code",1);
            jsonObject.put("msg","登录成功");
            session.setAttribute("name",name);
            return jsonObject;
        }
        jsonObject.put("code",0);
        jsonObject.put("msg","用户名或密码错误");
        return jsonObject;
    }
}


